#ifndef CHATSERVICE_H
#define CHATSERVICE_H

#include <muduo/net/TcpConnection.h>
#include <iostream>
#include <unordered_map>
#include <functional>
#include "json.hpp"
#include "public.hpp"
using json = nlohmann::json;
using namespace std::placeholders;

// 第一个参数是 对方的TcpConnection信息，第二个参数是对方发过来的完整信息，第三个参数是 时间
using handler = std::function<void(const muduo::net::TcpConnectionPtr& conn, json& js, muduo::Timestamp)>;

class ChatService
{
public:
    static ChatService *instance();

    void Login(const muduo::net::TcpConnectionPtr &conn,  json& js, muduo::Timestamp time);
   
    void Register(const muduo::net::TcpConnectionPtr &conn,  json& js, muduo::Timestamp time);
    
    handler getHandler(int messageid);
private:
    ChatService();
private:
    // 将MegType类设置为单例模式类
    std::unordered_map<int, handler> _MegHandlerMap;
};

#endif